<template>
  <div>
    <soltTitle>
      <van-search
        v-model="value"
        shape="round"
        show-action
        autofocus
        placeholder="客户名称/拜访标题"
        @search="onSearch"
      >
        <template #action>
          <div @click="onSearch" style="color:#1989fa">搜索</div>
        </template>
      </van-search>
    </soltTitle>
    <van-empty image="search" description="暂无结果" v-show='without'/>
  </div>
</template>
<script>
import soltTitle from "../../components/soltTitle";
import { GetDateAPI, GetCustDateAPI } from "../..//request/api";
import VisitListVue from "./VisitList.vue";

export default {
  data() {
    return {
      value: "",
      count: 1,
      without:false
    };
  },
  methods: {
    onSearch() {
      this.count++;
      if (this.$store.state.lastRouter) {
        GetDateAPI({
          keyword: this.value,
          current: this.count,
          size: 10
        }).then(res => {
          if (res.errCode == 0) {
            if (res.data.records.length==0) {
              this.without = true;
            } else {
              this.$store.commit("amendArr", res.data.records);
              this.$router.push("/visitrecord");
            }
          }
        });
      } else {
        GetCustDateAPI({
          keyword: this.value,
          current: 1 + "",
          size: 20 + ""
        }).then(res => {
          if (res.errCode == 0) {
            if (res.data.records.length==0) {
              this.without = true;
            } else {
              this.$store.commit("amendArr", res.data.records);
              this.$router.push("/visitlist");
            }
          }
        });
      }
    }
  },
  created() {
    console.log(this.$store.state.arr);
  },
  components: {
    soltTitle
  }
};
</script>

<style>
</style>